package servlets;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Container;

import javax.swing.JFrame;
import javax.swing.JPanel;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class SWTPanel extends JPanel {
	private static final long serialVersionUID = -1089789032409665511L;
	DisplayThread displayThread;
	private Canvas canvas;

	public SWTPanel() {
		displayThread = new DisplayThread();
		displayThread.start();
		canvas = new Canvas();
		setLayout(new BorderLayout());
		add(canvas, BorderLayout.CENTER);
	}

	public void addNotify() {
		super.addNotify();
		Display dis = displayThread.getDisplay();
		dis.syncExec(new Runnable() {
			public void run() {
				Shell shell = SWT_AWT.new_Shell(displayThread.getDisplay(),
						canvas);
				shell.setLayout(new FillLayout());
				final Browser browser = new Browser(shell, SWT.NONE);
				browser.setLayoutData(BorderLayout.CENTER);
				browser.setUrl("http://localhost:2016/manager/kindeditor-4.1.10/examples/default.html?editfile=%2Fajiaojie%2F%E5%AE%9E%E5%90%8D%E5%88%B6%E6%A8%A1%E5%9D%97.eclick");
			}
		});
	}
	
	public static void main(String[] args){
		JFrame mainFrame = new JFrame("Java Swing Examples");
		mainFrame.setSize(800,400);
		mainFrame.setLocation(500, 500);
		Container tt = mainFrame.getContentPane();
		SWTPanel panel = new SWTPanel();
		tt.add(panel);
		mainFrame.setAlwaysOnTop(true);
		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		mainFrame.setVisible(true);
	}
	
}
